package com.libweb.listener;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class LibWebSessionListener implements HttpSessionListener {

	//첫 번째 접속될 때 호출(세션이 시작될 때 호출)
	@Override
	public void sessionCreated(HttpSessionEvent arg0) {

		ServletContext application = 
			arg0.getSession().getServletContext();
		int total = (Integer)application.getAttribute("total");
		int current = (Integer)application.getAttribute("current");
		application.setAttribute("total", total + 1);
		application.setAttribute("current", current + 1);
	}
	
	//세션이 종료될 때 호출되는 메서드
	@Override
	public void sessionDestroyed(HttpSessionEvent arg0) {
		
		ServletContext application = 
			arg0.getSession().getServletContext();		
		int current = (Integer)application.getAttribute("current");		
		application.setAttribute("current", current - 1);
	}

}





